home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / tcoop.arc / TCOOP2.ARC / GBUTTON.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1991-10-26  |  2.5 KB  |  103 lines

  1. // gbutton.cpp: Graphics button class implementations
  2.  
  3. #include <string.h>
  4. #include "gbutton.h"
  5.  
  6. // ----------------------- TextButton ----------------------- 
  7.  
  8. TextButton::TextButton(char *S, char *F, int Ba, int Fa,
  9.                        ColorPak &Cp, ActionProc A)
  10. : Wso(Ba, Fa, Cp)
  11. {
  12.   strcpy(Str, S);
  13.   strcpy(Font, F);
  14.   SetSize(25, 25);  // Default size  
  15.   Action = A;
  16. }
  17.  
  18. void TextButton::ChangeText(char *S, char *F)
  19. // Re-displays the text on a button with the new string S and
  20. // the new font F 
  21. {
  22.   strcpy(Str, S);
  23.   strcpy(Font, F);
  24.   Draw();
  25. }
  26.  
  27. void TextButton::Draw(void)
  28. // Scales and writes the text within a button 
  29. {
  30.   if (*Str == 0) return;
  31.   Rso *Pint = Panel->Interior;
  32.   setusercharsize(1,1,1,1);
  33.   setusercharsize(Pint->Wd, textwidth(Str),
  34.                   Pint->Ht, textheight(Str) * 4 / 3);
  35.   // Clear out where text is to appear 
  36.   Mouse.Hide();
  37.   Pint->Fill(0, 0, Pint->Wd, Pint->Ht, ' ', Panel->Colors.Wc);
  38.   // Write the text centered on the face of the button 
  39.   setviewport(Pint->Xul,Pint->Yul,Pint->Xlr,Pint->Ylr,True);
  40.   setcolor(ForeGround(Panel->Colors.Wc));
  41.   settextjustify(CENTER_TEXT, CENTER_TEXT);
  42.   outtextxy(Pint->Wd/2+2, Pint->Ht/2, Str);
  43.   // Restore clip region to whole screen 
  44.   setviewport(0, 0, getmaxx(), getmaxy(), True);
  45.   Mouse.Show();
  46. }
  47.  
  48. void TextButton::Activate(MsgPkt &M)
  49. // Performs the buttons action if the object is currently
  50. // selected, else the button is de-selected 
  51. {
  52.   if (Active) {
  53.     Wso::Activate(M);
  54.     Action(this, M);
  55.   }
  56.   else Leave(M);
  57. }
  58.  
  59. // ----------------------- IconButton -------------------------- 
  60.  
  61. IconButton::IconButton(DrawProc D, int Ba, int Fa, 
  62.                        ColorPak &Cp, ActionProc A)
  63. : Wso(Ba, Fa, Cp)
  64. {
  65.   SetSize(25, 25);  // Default size  
  66.   DrawIcon = D;
  67.   Action = A;
  68. }
  69.  
  70. void IconButton::Draw(void)
  71. // Draws the icon in the button's interior after calling
  72. // the inherited version of Draw 
  73. {
  74.   Wso::Draw();
  75.   DrawIcon(this);
  76. }
  77.  
  78. void IconButton::Activate(MsgPkt &M)
  79. // Performs the buttons action if the object is currently
  80. // selected, else the button is de-selected 
  81. {
  82.   if (Active) {
  83.      Wso::Activate(M);
  84.      Action(this, M);
  85.   }
  86.   else Leave(M);
  87. }
  88.  
  89. // ------------- Common button actions defined ----------- 
  90.  
  91. void NoOp(Wso *, MsgPkt &)
  92. // A sample action that doesn't do anything 
  93. {
  94.   ;
  95. }
  96.  
  97. void ExitAction(Wso *, MsgPkt &M)
  98. // A sample action that causes the window system to shutdown 
  99. {
  100.   M.RtnCode = ShutDown;
  101. }
  102.  
  103.